package com.bs.message.web.rest;

import com.bs.ei.EIInfo;
import com.bs.message.service.RabbitmqService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author J
 */
@RestController
@RequestMapping("/api/message")
public class RabbitmqController {
    private final RabbitmqService rabbitmqService;

    @Autowired
    public RabbitmqController(RabbitmqService rabbitmqService) {
        this.rabbitmqService = rabbitmqService;
    }

    @PostMapping(value = "/send")
    public EIInfo send(@RequestBody EIInfo info){
        EIInfo eiInfo = new EIInfo();
        try {
            eiInfo = rabbitmqService.send(info);
            eiInfo.getSysInfo().setFlag(0);
            eiInfo.getSysInfo().setMsg("Successful");
        } catch (Exception ex) {
            eiInfo.getSysInfo().setFlag(-1);
            eiInfo.getSysInfo().setMsg("Failed,error msg:" + ex.getMessage());
        }
        return eiInfo;
    }
}
